package org.sanm.utils;

import org.apache.commons.lang3.RandomStringUtils;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * @author zhengm
 */
public class RandomUtil {
    public static String genUuidAndMill() {
        return UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis();
    }

    public static String genRandomCode(int length) {
        return RandomStringUtils.randomNumeric(length);
    }

    public static String genUuid() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    public synchronized static String genMillAndRandomNo(int length) {
        return System.currentTimeMillis() + (genRandomCode(length));
    }

    public static String genYmdAndRandomCode() {
        return genRandomCode(8) + DateUtil.localDateTimeToStrNoSeparate(LocalDateTime.now());
    }

    public static String genYmdAndRandomCode(String bizUnique) {
        return bizUnique + genRandomCode(8) + DateUtil.localDateTimeToStrNoSeparate(LocalDateTime.now());
    }
}
